#ifndef VIEWCAMERA_H
#define VIEWCAMERA_H

#include <QVector3D>
#include <QMatrix4x4>
#include <QQuaternion>
#include <QMouseEvent>

class ViewCamera {
public:
    ViewCamera();

    void setMouseLockedStatus(bool locked);
    void setSensitivity(float mouse_sensitivity);
    void setPerspective(float aspect, float nearPlane, float farPlane);
    void lookAt(const QVector3D &eye, const QVector3D &center, const QVector3D &up);

    void surroundOriginByMouseInput(const QPoint &mouseDelta);

    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);
    void wheelEvent(QWheelEvent *event);

    QVector3D getEye()
    {
        return m_eye;
    }

    QMatrix4x4 getViewMatrix() const;
    QMatrix4x4 getProjectionMatrix() const;

private:
    QVector3D m_eye;
    QVector3D m_center;
    QVector3D m_up;

    QMatrix4x4 m_view;
    QMatrix4x4 m_projection;

    float m_yaw;   // 偏航角（左右旋转）
    float m_pitch; // 俯仰角（上下旋转）
    float m_fov;   // 相机视野

    bool m_mouseLocked; // 是否锁定鼠标
    float m_sensitivity = 0.1f; // 鼠标灵敏度
};

#endif // VIEWCAMERA_H
